# _*_ coding : utf-8 _*_
# @Time : 2023/3/17 0017 11:09
# @Author : 菜鸟王小二
# @File : 24_selenium基本使用
# @Project : python爬虫
import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

# 定义chrome驱动地址
path = Service('E:/chromedriver/chromedriver.exe')

# 创建浏览器操作对象,再去调用上面的path,这样终端不会报这个错:
#    DeprecationWarning: executable_path has been deprecated, please pass in a Service objectbrowser = webdriver.Chrome(path)
driver = webdriver.Chrome(service=path)
driver.implicitly_wait(5)

driver.get('https://www.jd.com')

# input = driver.find_element(By.ID, 'key')
# 通过属性名获取属性值
# print(input.get_attribute('class'))

button = driver.find_element(By.XPATH,'//div[@id="navitems"]//a[@class="navitems-lk"]')
# 获取元素的文本
print(button.text)

time.sleep(3)
# 返回页面数据
# print(driver.page_source)

driver.quit()